package com.heima.media.controller;

import com.heima.common.util.RequestContextUtil;
import com.heima.media.service.WmMaterialService;
import com.heima.model.common.dtos.PageRequestDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.media.pojos.WmMaterial;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping(value = "/api/v1/material")
public class WmMaterialController {
    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * 自媒体分页查询
     */
    @PostMapping(value = "/search")
    public ResponseResult search(@RequestBody PageRequestDto<WmMaterial>dto){
       return wmMaterialService.search(dto);

    }


    /**
     * 素材增加
     */
    @PostMapping
    public ResponseResult add(@RequestBody WmMaterial wmMaterial){
        wmMaterial.setUserId(RequestContextUtil.getNode("id"));
        wmMaterial.setType(0);
        wmMaterial.setIsCollection(0);
        wmMaterial.setCreatedTime(new Date());
        wmMaterialService.save(wmMaterial);
        return ResponseResult.okResult(null);

    }

}
